package com.exam.Mapper;

import com.exam.Entity.Student;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface StudentMapper {

//    /**
//     * 分页查询所有学生
//     * @param page
//     * @return List<Student>
//     */
    @Select("select * from student")
    List<Student> findAll();

//    @Select("select * from student")
//    List<Student> findAll(int page, int size);

    @Select("select * from student where sno = #{sno}")
    Student findById(Integer sno);

    @Delete("delete from student where sno = #{sno}")
    int deleteById(Integer sno);

    /**
     *更新所有学生信息
     * @param student 传递一个对象
     * @return 受影响的记录条数
     */
    @Update("update student set sname = #{sname},major = #{major},gender = #{gender}," +
            "password = #{password},phoneNumber = #{phoneNumber},email = #{email} " +
            "where sno = #{sno}")
    int update(Student student);

    /**
     * 更新密码
     * @param student
     * @return 受影响的记录条数
     */
    @Update("update student set password = #{password} where sno = #{sno}")
    int updatePwd(Student student);


    @Options(useGeneratedKeys = true,keyProperty = "studentId")
    @Insert("insert into student(sname,sno,major,gender,password,phoneNumber,email) values " +
            "(#{sname},#{sno},#{major},#{gender},#{password},#{phoneNumber},#{email})")
    int add(Student student);
}
